package com.boot.controller;

import com.boot.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    public static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    UserService userService;

    @GetMapping("/login")
    public String login(){
        logger.debug("进入登录接口");
        return "manager/login";
    }

    @GetMapping("/doLogin")
    @ResponseBody
    public String doLogin(HttpSession session,String userName, String password){
        logger.debug("进入登录接口 用户名:{},密码:{}",userName,password);

        String ret = userService.doLogin(userName,password);

        if(ret.equals("success")){
            session.setAttribute("userName",userName);
        }
        return ret;
    }



}
